import org.dom4j.Element
import org.dom4j.io.SAXReader
import java.io.File


fun main(args: Array<String>) {
    print(Pug(System.getProperty("user.dir") + "/pom.xml"))
}

private val xmlReader = SAXReader()

class Pug(path: String) {
    private val sb = StringBuilder()

    init {
        xmlReader.read(File(path)).rootElement.elements().forEach { add(it, 0) }
    }

    private fun add(e: Element, indent: Int) {
        sb.append("\t".repeat(indent) + e.name)

        val attributes = e.attributes()
        if (attributes.size != 0)
            sb.append(attributes.joinToString(" ", "(", ")") { it.name + "=\"" + it.value + '"' })


        sb.appendln(" " + e.text.replace("\n", ""))
        e.elements().forEach { add(it, indent + 1) }
    }

    override fun toString(): String {
        return sb.toString()
    }
}